package com.hymall.service.wx;

import com.hymall.bean.MarketOrder;
import com.hymall.bean.MarketOrderExample;
import com.hymall.bean.MarketUser;
import com.hymall.bean.MarketUserExample;
import com.hymall.bean.vo.WxUserIndexInnerOrderVO;
import com.hymall.bean.vo.WxUserIndexVO;
import com.hymall.mapper.MarketOrderMapper;
import com.hymall.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 章鹏
 * @description 用户（登录后） → 个人中心
 * @date: 2022/7/19 9:48
 */
@Service
public class WxUserServiceImpl implements WxUserService {



    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Override
    public WxUserIndexVO index(MarketUser marketUser) {
        Integer id = marketUser.getId();
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria = marketOrderExample.createCriteria();
        criteria.andUserIdEqualTo(id);
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(marketOrderExample);
        int unrecv=0;
        int uncoment=0;
        int unpaid=0;
        int unship=0;
        for (MarketOrder order : marketOrders) {
            uncoment+=order.getComments();
            if ("101".equals(order.getOrderStatus().toString())){
                unpaid++;
            }else if ("201".equals(order.getOrderStatus().toString())){
                unship++;
            }else if ("301".equals(order.getOrderStatus().toString())){
                unrecv++;
            }
        }
        WxUserIndexInnerOrderVO wxUserIndexInnerOrderVO = new WxUserIndexInnerOrderVO();
        wxUserIndexInnerOrderVO.setUncomment(uncoment);
        wxUserIndexInnerOrderVO.setUnpaid(unpaid);
        wxUserIndexInnerOrderVO.setUnrecv(unrecv);
        wxUserIndexInnerOrderVO.setUnship(unship);
        WxUserIndexVO wxUserIndexVO = new WxUserIndexVO();
        wxUserIndexVO.setOrder(wxUserIndexInnerOrderVO);
        return wxUserIndexVO;
    }

}
